Add TAL-Reverb-II plugin to test
[juce-lv2.git] / juce / source / extras / the jucer / src / model / documents / jucer_ComponentDocument.cpp
blob96faa748db282102e298dff731a1c02361c3d9f2
1 /*
2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #include "../../jucer_Headers.h"
27 #include "jucer_ComponentDocument.h"
30 //==============================================================================
31 ComponentDocument::ComponentDocument()
33 components = new ComponentLayout();
34 components->setDocument (this);
36 backgroundGraphics = new PaintRoutine();
37 backgroundGraphics->setDocument (this);
40 ComponentDocument::~ComponentDocument()
42 delete components;
43 delete backgroundGraphics;
46 //==============================================================================
47 const String ComponentDocument::getTypeName() const
49 return "Component";
52 JucerDocument* ComponentDocument::createCopy()
54 ComponentDocument* newOne = new ComponentDocument();
56 newOne->resources = resources;
57 newOne->setFile (getFile());
59 XmlElement* const xml = createXml();
60 newOne->loadFromXml (*xml);
61 delete xml;
63 return newOne;
66 XmlElement* ComponentDocument::createXml() const
68 XmlElement* const doc = JucerDocument::createXml();
70 doc->addChildElement (backgroundGraphics->createXml());
71 components->addToXml (*doc);
73 return doc;
76 bool ComponentDocument::loadFromXml (const XmlElement& xml)
78 if (JucerDocument::loadFromXml (xml))
80 components->clearComponents();
82 forEachXmlChildElement (xml, e)
84 if (e->hasTagName (PaintRoutine::xmlTagName))
85 backgroundGraphics->loadFromXml (*e);
86 else
87 components->addComponentFromXml (*e, false);
90 changed();
91 getUndoManager().clearUndoHistory();
92 return true;
95 return false;
98 //==============================================================================
99 class NormalTestComponent : public Component
101 public:
102 NormalTestComponent (ComponentDocument* const document_, const bool alwaysFillBackground_)
103 : document (document_),
104 alwaysFillBackground (alwaysFillBackground_)
106 ComponentLayout* const layout = document->getComponentLayout();
108 for (int i = 0; i < layout->getNumComponents(); ++i)
109 addAndMakeVisible (layout->getComponent (i));
112 ~NormalTestComponent()
114 for (int i = getNumChildComponents(); --i >= 0;)
115 removeChildComponent (i);
118 void paint (Graphics& g)
120 document->getPaintRoutine (0)->fillWithBackground (g, alwaysFillBackground);
121 document->getPaintRoutine (0)->drawElements (g, Rectangle<int> (0, 0, getWidth(), getHeight()));
124 void resized()
126 if (! getBounds().isEmpty())
128 int numTimesToTry = 10;
130 while (--numTimesToTry >= 0)
132 bool anyCompsMoved = false;
134 for (int i = 0; i < getNumChildComponents(); ++i)
136 Component* comp = getChildComponent (i);
137 ComponentTypeHandler* const type = ComponentTypeHandler::getHandlerFor (*comp);
139 if (type != 0)
141 const Rectangle<int> newBounds (type->getComponentPosition (comp)
142 .getRectangle (Rectangle<int> (0, 0, getWidth(), getHeight()),
143 document->getComponentLayout()));
145 anyCompsMoved = anyCompsMoved || (comp->getBounds() != newBounds);
146 comp->setBounds (newBounds);
150 // repeat this loop until they've all stopped shuffling (might require a few
151 // loops for all the relative positioned comps to settle down)
152 if (! anyCompsMoved)
153 break;
158 private:
159 ComponentDocument* const document;
160 const bool alwaysFillBackground;
163 Component* ComponentDocument::createTestComponent (const bool alwaysFillBackground)
165 return new NormalTestComponent (this, alwaysFillBackground);
168 //==============================================================================
169 void ComponentDocument::fillInGeneratedCode (GeneratedCode& code) const
171 JucerDocument::fillInGeneratedCode (code);